﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>
/// Summary description for DBConn
/// </summary>

    public class DBConn
    {
        private string ConnectionName = ConfigurationManager.AppSettings["DBConnectionName"];
        private string ConnectionString;

        private SqlConnection _DBConnection;
        public SqlConnection DBConnection
        {
            get
            {
                return _DBConnection;
            }
            set
            {
                _DBConnection = value;
            }
        }

        public DBConn()
        {
            ConnectionString = ConfigurationManager.ConnectionStrings[ConnectionName].ConnectionString;
            DBConnection = new SqlConnection(ConnectionString);
        }

        public void OpenConnection()
        {
            DBConnection.Open();
        }

        public void Disconnect()
        {
            if (DBConnection.State == System.Data.ConnectionState.Open)
            {
                DBConnection.Close();
            }
            DBConnection.Dispose();
        }
    }
